package cn.edu.nuc.onlinestore.start;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import cn.edu.nuc.onlinestore.frame.AdminLogin;
import cn.edu.nuc.onlinestore.frame.UserLogin;

import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ChooseServer extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6784255560706498226L;
	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JFrame frame;
	private String ip;
	private int dk;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ChooseServer frame = new ChooseServer();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public String getIp() {
		return ip;
	}

	public int getDk() {
		return dk;
	}

	/**
	 * Create the frame.
	 */
	public ChooseServer() {
		this.frame=this;
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblip = new JLabel("请输入IP：");
		lblip.setBounds(70, 51, 68, 15);
		contentPane.add(lblip);
		
		textField = new JTextField();
		textField.setText("127.0.0.1");
		textField.setBounds(148, 48, 168, 21);
		contentPane.add(textField);
		textField.setColumns(20);
		
		JLabel label = new JLabel("请输入端口：");
		label.setBounds(70, 97, 82, 15);
		contentPane.add(label);
		
		textField_1 = new JTextField();
		textField_1.setText("8000");
		textField_1.setBounds(148, 94, 168, 21);
		contentPane.add(textField_1);
		textField_1.setColumns(10);
		
		JButton button = new JButton("管理员入口");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ip=textField.getText();
				dk=Integer.parseInt(textField_1.getText());
				System.out.println(ip+" "+dk);
				frame.setVisible(false);
				AdminLogin frame = new AdminLogin(ip,dk);
				frame.setVisible(true);
			}
		});
		button.setBounds(223, 141,100, 23);
		contentPane.add(button);
		JButton button1 = new JButton("普通用户入口");
		button1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ip=textField.getText();
				dk=Integer.parseInt(textField_1.getText());
				System.out.println(ip+" "+dk);
				frame.setVisible(false);
				UserLogin frame = new UserLogin(ip,dk);
				frame.setVisible(true);
			}
		});
		button1.setBounds(100, 141,120, 23);
		contentPane.add(button1);
	}
}
